#!/bin/bash

# This is an example for packaging a commercial Java application as an AppImage.

APP=PyCharm
mkdir -p $APP/$APP.AppDir/usr/bin

cd $APP/

wget -q https://github.com/AppImage/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh

# wget -c "https://download.jetbrains.com/python/pycharm-community-5.0.4.tar.gz"
wget -c "https://download.jetbrains.com/python/pycharm-community-2016.3.2.tar.gz"

# Get Java
wget -c --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jre-8u66-linux-x64.tar.gz

cd $APP.AppDir/

get_apprun

tar xf ../pycharm-*.tar.gz 
( mkdir -p usr/bin/bin ; cd usr/bin; ln -s ../../pycharm-community-*/bin/pycharm.sh . )

# Install java
tar xf ../jre*
( cd ./pycharm-community-* ; mkdir -p jre ; cd jre ; mv ../../jre* ./jre )

cat > pycharm.desktop <<\EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=PyCharm Community Edition
Icon=pycharm
Exec=pycharm.sh
Comment=Develop with pleasure!
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-pycharm-ce
EOF

cp ./pycharm-*/bin/pycharm.png .

VERSION=$(ls ../pycharm-community-* | cut -d - -f 3 | sed 's|.tar.gz||g')
echo $VERSION

# Do not add desktop integration since it comes with its own

cd .. # Go out of AppDir

generate_type2_appimage
